home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / packet / tf27bsrc / l2.h < prev    next >
Text File  |  1995-05-23  |  22KB  |  345 lines

  1. /**************************************************************************\
  2. *                                                                          *
  3. *                                                                          *
  4. *    *****                      *****                                      *
  5. *      *****                  *****                                        *
  6. *        *****              *****                                          *
  7. *          *****          *****                                            *
  8. *            *****      *****                                              *
  9. *              *****  *****                                                *
  10. *            *****      *****                                              *
  11. *          *****          *****          The Firmware.                     *
  12. *        *****              *****        Portable. Compatible.             *
  13. *      *****                  *****      Public Domain.                    *
  14. *    *****                      *****    By NORD><LINK.                    *
  15. *                                                                          *
  16. *                                                                          *
  17. *                                                                          *
  18. *    L2.H   -   Headerfile Level 2                                         *
  19. *                                                                          *
  20. *    angelegt:      DC4OX                                                  *
  21. *    modifiziert:   DL8ZAW, 27.04.91                                       *
  22. *                   L2CDAMA = DAMA-Bit in SSID (0=DAMA-Master)             *
  23. *                   LNKBLK: RTT, IRTT, SRTT fuer RTT-Messung zugefuegt     *
  24. *                                                                          *
  25. *                   DL8ZAW, 07.05.91                                       *
  26. *                   L2FDPOLL = Im DAMA-Modus ersten Poll uebergehen        *
  27. *                              (siehe L2A.C)                               *
  28. *                                                                          *
  29. *                   DL8ZAW, 27.03.92                                       *
  30. *                   TheNet spezifischer Code entfernt                      *
  31. *                                                                          *
  32. *                   DL4YBG, 23.10.93                                       *
  33. *                   LNKBLK: IT1 hinzugefuegt                               *
  34. *                   RTTMAX,RTTMIN neu                                      *
  35. *                                                                          *
  36. *                   DG2FEF, 18.06.94                                       *
  37. *                   L2FJSENT = 1, wenn ein Frame noch in der TX-Queue ist  *
  38. *                              das bei DAMA wegen sendok==0 noch nicht     *
  39. *                              rausgegangen ist                            *
  40. *                                                                          *
  41. *                   DG2FEF, 18.07.94                                       *
  42. *                   L2FRETRY,L2FMAXF1: Flags für Framesammler-             *
  43. *                                      Unterstützung                       *
  44. *                   L2FDIRTY: RTT-Messung ungültig                         *
  45. *                   L2FPOLL: Link wurde unter DAMA gepollt                 *
  46. *                   LNKBLK: oldVS, RTTNR angehängt                         *
  47. *                   L2FL3LNK: Entfernt, wird nicht benötigt                *
  48. *                                                                          *
  49. *                   DG2FEF, 13.08.94                                       *
  50. *                   L2FDAMA ersetzt L2FRETRY                               *
  51. *                                                                          *
  52. *                   DB2OS, 12.08.94                                        *
  53. *                   überflüssige noatou-Varibale und MHEARD entfernt.      *
  54. \**************************************************************************/
  55.  
  56.  
  57.  
  58.  
  59.  
  60. /*                                                         Festlegungen   */
  61. /**************************************************************************/
  62.  
  63. #define L2PNUM   1                      /* TheFirmware :  1 Level-2-Port  */
  64.  
  65. #define L2CALEN  6                      /* Laenge Call im Level 2         */
  66. #define L2IDLEN  (L2CALEN + 1)          /* Laenge Call + SSID = ID        */
  67. #define L2INUM   2                      /* Anzahl ID's im an/von-Feld     */
  68. #define L2VNUM   8                      /* Anzahl ID's im via-Feld        */
  69. #define L2ILEN   (L2INUM * L2IDLEN)     /* Laenge an/von-Feld             */
  70. #define L2VLEN   (L2VNUM * L2IDLEN)     /* Laenge via-Feld                */
  71. #define L2AFLEN  (L2ILEN + L2VLEN)      /* Laenge Level 2 Adressfeld      */
  72. #define L2MFLEN  328                    /* maximale Framelaenge,          */
  73.                                         /*   10 * 7 =    70 Bytes Adresse */
  74.                                         /*            +   1 Byte Control  */
  75.                                         /*            +   1 Byte PID      */
  76.                                         /*            + 256 Byte Info     */
  77.                                         /*            -----               */
  78.                                         /*              328               */
  79.  
  80.  
  81.  
  82.                               /* "layer 2 state", (state, s.u.) :         */
  83. #define L2SDSCED    0         /*    disconnected                          */
  84. #define L2SLKSUP    1         /*    link setup                            */
  85. #define L2SFRREJ    2         /*    frame reject                          */
  86. #define L2SDSCRQ    3         /*    disconnect request                    */
  87. #define L2SIXFER    4         /*    information transfer                  */
  88. #define L2SRS       5         /*    REJ sent                              */
  89. #define L2SWA       6         /*    waiting acknowledge                   */
  90. #define L2SDBS      7         /*    device busy                           */
  91. #define L2SRBS      8         /*    remote busy                           */
  92. #define L2SBBS      9         /*    both busy                             */
  93. #define L2SWADBS   10         /*    waiting ack and device busy           */
  94. #define L2SWARBS   11         /*    waiting ack and remote busy           */
  95. #define L2SWABBS   12         /*    waiting ack and both busy             */
  96. #define L2SRSDBS   13         /*    REJ sent and device busy              */
  97. #define L2SRSRBS   14         /*    REJ sent and remote busy              */
  98. #define L2SRSBBS   15         /*    REJ sent and both busy                */
  99.  
  100.  
  101.  
  102.                               /* "layer 2 message", Status vom Level 2 :  */
  103. #define L2MNIX     0          /*    keine Nachricht                       */
  104. #define L2MCONNT   1          /*    CONNECTED to                          */
  105. #define L2MDISCF   2          /*    DISCONNECTED from                     */
  106. #define L2MBUSYF   3          /*    BUSY from                             */
  107. #define L2MFAILW   4          /*    LINK FAILURE with                     */
  108. #define L2MLRESF   5          /*    LINK RESET from                       */
  109. #define L2MLREST   6          /*    LINK RESET to                         */
  110. #define L2MFRMRF   7          /*    FRAME REJECT from                     */
  111. #define L2MFRMRT   8          /*    FRAME REJECT to                       */
  112. #define L2MBUSYT   9          /*    BUSY to                               */
  113.  
  114.  
  115.  
  116.                               /* "layer 2 control", Frametypen :          */
  117.                               /*                                          */
  118.                               /*                       Command/   Poll/   */
  119.                               /*    Typ       Gruppe   Response   Final   */
  120.                               /* ---------------------------------------- */
  121. #define L2CI       0x00       /*      I         I         C         P     */
  122. #define L2CUI      0x03       /*     UI         U        C/R       P/F    */
  123. #define L2CSABM    0x2F       /*   SABM         U         C         P     */
  124. #define L2CDISC    0x43       /*   DISC         U         C         P     */
  125. #define L2CUA      0x63       /*     UA         U         R         F     */
  126. #define L2CDM      0x0F       /*     DM         U         R         F     */
  127. #define L2CFRMR    0x87       /*   FRMR         U         R         F     */
  128. #define L2CRR      0x01       /*     RR         S        C/R       P/F    */
  129. #define L2CREJ     0x09       /*    REJ         S        C/R       P/F    */
  130. #define L2CRNR     0x05       /*    RNR         S        C/R       P/F    */
  131.  
  132.                               /* "layer 2 control", spezielle Bits :      */
  133. #define L2CPF      0x10       /*   Poll/Final                             */
  134. #define L2CCR      0x80       /*   Command/Response                       */
  135. #define L2CH       0x80       /*   "has been repeated"                    */
  136. #define L2CEOA     0x01       /*   End of Address                         */
  137. #define L2CDAMA    0x20       /*   DAMA-Bit in SSID (0=DAMA Master)       */
  138.  
  139.                               /* "layer 2 control", Masken :              */
  140. #define L2CNOIM    0x01       /*   "no I mask", kein I-Frame              */
  141. #define L2CNOSM    0x02       /*   "no S mask", kein S-Frame              */
  142. #define L2CNONRM   0x03       /*   "no N(R) mask", kein N(R)-Frame        */
  143.  
  144.                               /* "layer 2 control", Protokollidentifier   */
  145. #define L2CPID     0xF0       /*   PID                                    */
  146.  
  147.                               /* "layer 2 control", Flags (flag, s.u.) :  */
  148. #define L2FIRCVD   0x01       /* FEF es wurde ein I-Frame empfangen       */
  149. #define L2FDIRTY   0x02       /* FEF Die lfd. RTT-Messung ist ungültig    */
  150. #define L2FMAXF1   0x04       /* FEF Auf dem Link gilt Maxframe 1         */
  151. #define L2FDAMA    0x08       /* FEF Auf dem Link stehen noch Frames aus  */
  152. #define L2FJSENT   0x10       /* FEF Auf dem Link wurde gerade gesendet,  */
  153.                               /*     es ist noch nichts zu retryen        */
  154. #define L2FPOLL    0x20       /* FEF Link wurde unter DAMA gepollt        */
  155. #define L2FBUSY    0x40       /*   Device busy (ich !)                    */
  156. #define L2FDSLE    0x80       /*   "disc if send list empty"              */
  157.  
  158.                               /* im Framebufferkopf (l2fflag, s.u.) :     */
  159. #define L2FT1ST    0x01       /*   nach Aussendung ist T1 zu starten      */
  160. #define L2FUS      0x02       /*   Sendeframe ist U- oder S-Frame (nicht  */
  161.                               /*   digipeatet)                            */
  162. #define L2FRTTST   0x04
  163.  
  164. #define RTTMAX     4095       /* max-wert RTT 40950ms (DL4YBG)            */
  165. #define RTTMIN     10         /* min-wert RTT 100ms (DL4YBG)              */
  166.  
  167.                               /* Anzahl Buffer pro Link nach DB7KG        */
  168. #define MAXLBUF ((nmbfre*sizeof(MB))/(nmblks+1))
  169.  
  170. /*                                                                Typen   */
  171. /**************************************************************************/
  172.  
  173.  
  174.  
  175. typedef struct lhead          /* "list head", Listenkopf :                */
  176.   {
  177.     struct lhead   *head;     /*   Zeiger auf ersten Eintrag in Liste     */
  178.     struct lhead   *tail;     /*   Zeiger auf letzten Eintrag in Liste    */
  179.   } LHEAD;
  180.  
  181.  
  182.  
  183. typedef struct lehead         /* "list entry head", Kopf eines Eintrags   */
  184.   {                           /* in Liste :                               */
  185.     struct lehead   *nextle;  /*   Zeiger auf naechsten Listeneintrag     */
  186.     struct lehead   *prevle;  /*   Zeiger auf vorherigen Listeneintrag    */
  187.   } LEHEAD;
  188.  
  189.  
  190.  
  191. typedef struct lnkblk         /* "link block", fuer jeden Level-2-Link :  */
  192.   {
  193.     char     state;           /* Link-State, s.o. L2S...                  */
  194.     char     srcid[L2IDLEN];  /* "source id", eigenes Call/SSID oder      */
  195.                               /* Ident/SSID                               */
  196.     char     dstid[L2IDLEN];  /* "destination id", Call/SSID Gegenstation */
  197.     char     viaidl[L2VLEN+1];/* "via id list", Digipeaterstrecke,        */
  198.                               /* 0-terminiert, Weg zur Gegenstation       */
  199.     char     liport;          /* "link port" - 0 : HDLC, 1 : Crosslink    */
  200.     char     VR;              /* "receive sequence variable", Sequenz-    */
  201.                               /* nummer des naechsten zu empfangenden     */
  202.                               /* I-Frames                                 */
  203.     char     VS;              /* "send sequence variable", Sequenznummer  */
  204.                               /* des naechsten zu sendenden I-Frames      */
  205.     char     lrxdNR;          /* "last received N(R)", zuletzt            */
  206.                               /* empfangenes N(R) = eigene gesendete      */
  207.                               /* I-Frames bis lrxdNR-1 bestaetigt         */
  208.     char     ltxdNR;          /* "last transmitted N(R)", zuletzt         */
  209.                               /* gesendetes N(R) = empfangene I-Frames    */
  210.                               /* bis ltxdNR-1 bestaetigt                  */
  211.     char     tries;           /* aktuelle Anzahl Versuche (RETRY),        */
  212.                               /* hochzaehlend                             */
  213.     char     N2;              /* RETRY, maximale Anzahl Retries           */
  214.     char     k;               /* MAXFRAME, maximale Anzahl unbestaetigter */
  215.                               /* I-Frames                                 */
  216.     char     RStype;          /* "response supervisory frametype", nach   */
  217.                               /* T2-Ablauf zu sendendes Antwortframe      */
  218.                               /* (RR=0x01, RNR=0x05, REJ=0x09)            */
  219.     char     frmr[3];         /* die 3 FRMR-Infobytes, Sendung u. Empfang */
  220.                               /*   frmr[0] : zurueckgewies. Kontrollfeld  */
  221.                               /*   frmr[1] : V(R) CR V(S) 0               */
  222.                               /*   frmr[2] : 0000ZYXW                     */
  223.     char     flag;            /* Flag (s.o. L2F... )                      */
  224.                               /*   Bit 0 : nicht benutzt                  */
  225.                               /*   Bit 1 : FEF RTT-Messung ungültig       */
  226.                               /*   Bit 2 : FEF Maxframe 1 wird erzwungen  */
  227.                               /*   Bit 3 : Signal, daß auf dem Link noch  */
  228.                               /*   FEF     unbestätigte Frames ausstehen  */
  229.                               /*                                          */
  230.                               /*   Bit 4 : Auf dem Link befindet sich ein */
  231.                               /*           Frame in der TX-Queue, das aber*/
  232.                               /*   FEF     wegen sendok==0 möglicherweise */
  233.                               /*           nicht gesendet wurde           */
  234.                               /*   Bit 5 : FEF Link wurde unter DAMA ge-  */
  235.                               /*           pollt                          */
  236.                               /*   Bit 6 : 1 = (eigenes) Device busy      */
  237.                               /*   Bit 7 : 1 = Link disconnecten, sobald  */
  238.                               /*           Sendeliste (sendil) leer ist   */
  239.     unsigned IRTT;            /* "Initial Round Trip Time" = Anfangswert  */
  240.     unsigned RTT;             /* Round-Trip-Timer (10 ms)                 */
  241.     unsigned SRTT;            /* Smoothed Round Trip Timer                */
  242.                               /* SRTT = (Alpha x SRTT + RTT)/(Alpha + 1)  */
  243.     /* [DL4YBG] */
  244.     unsigned IT1;             /* Init-Wert fuer Timer 1 (a3*SRTT)         */
  245.                               /* noetig, da T1-Timer jetzt aus Interrupt  */
  246.                               /* gestartet wird (l1get) und eine Multi-   */
  247.                               /* plikation mit a3 zuviel Zeit kostet      */
  248.     /* ende */
  249.     unsigned T1;              /* Timer 1, "frame acknowledge interval",   */
  250.                               /* Start :  SRTT,                           */
  251.                               /* 0 = inaktiv, 10 msec Downcounter         */
  252.     unsigned T2;              /* Timer T2, "response delay timer",        */
  253.                               /* 0 = inaktiv, 10 msec Downcounter         */
  254.     unsigned T3;              /* Timer T3, "inactive link timer",         */
  255.                               /* 0 = inaktiv, 10 msec Downcounter         */
  256.     unsigned rcvd;            /* "received", Anzahl empfangener I-Frames  */
  257.                               /* in rcvdil                                */
  258.     unsigned tosend;          /* Anzahl noch nicht gesendete oder         */
  259.                               /* unbestaetigte Frames in sendil           */
  260.     LHEAD    rcvdil;          /* "received info list", richtig            */
  261.                               /* empfangene I-Frames, mit Header/PID      */
  262.     LHEAD    sendil;          /* "send info list", zu sendende I-Frames,  */
  263.                               /* ohne Header/PID, nur Info                */
  264.     char     oldVS;           /* FEF V(S) Backup für Framesammler         */
  265.     char     RTTNR;           /* FEF V(S), bei der RTT-Messung anlief     */
  266.  
  267.                               /* Framesammler:                            */
  268.     char     colled;          /* "collected", Anzahl I-Frames in collil   */
  269.     LHEAD    collil;          /* "collector info list", gesammelte I's    */
  270.     char     lastVR;          /* V(R) nach Aufräumen des Framesammlers    */
  271.     char     xpctVR;          /* FEF */
  272.                               /* nötigt für die Bestätigung via Statetbl. */
  273.   } LNKBLK;
  274.  
  275.  
  276.  
  277. typedef struct timebl              /* "time block", Zeit/Datums-Stamp :   */
  278.   {
  279.     char             second;       /*   Zeit :    Sekunde   (0..59)       */
  280.     char             minute;       /*             Minute    (0..59)       */
  281.     char             hour;         /*             Stunde    (0..23)       */
  282.     char             day;          /*   Datum :   Tag       (1..31)       */
  283.     char             month;        /*             Monat     (1..12)       */
  284.     char             year;         /*             Jahr      (0..99)       */
  285.   } TIMEBL;
  286.  
  287. /* ACHTUNG: mbhead und mb nun 32 Bytes länger ! DG2FEF, 13.08.94 */
  288.  
  289. /* ACHTUNG: mbhead muss genauso lang sein wie mb !                        */
  290.  
  291. typedef struct mbhead         /* "message buffer head",                   */
  292.   {                           /* Datenbuffer-Liste, Kopf :                */
  293.     struct mbhead   *nextmh;  /*   naechster Eintrag in Liste             */
  294.     struct mbhead   *prevmh;  /*   vorheriger Eintrag in Liste            */
  295.     LHEAD            mbl;     /*   "message buffer list", Zeiger auf      */
  296.                               /*   ersten Infobuffer dieser Message       */
  297.     char            *mbbp;    /*   "message buffer buffer pointer",       */
  298.                               /*   Zeiger auf aktuelles Zeichen in Buffer */
  299.     unsigned         mbpc;    /*   "message buffer put count",            */
  300.                               /*   Einschreibzaehler, aufwaertszaehlend   */
  301.     unsigned         mbgc;    /*   "message buffer get count",            */
  302.                               /*   Lesezaehler, aufwaertszaehlend         */
  303.     struct lnkblk   *l2link;  /*   Zeiger auf assozierten Linkblock       */
  304.     char             type;    /*   Typ des Buffers (User, Status)         */
  305.                               /*          L2M...                          */
  306.                               /*     oder MB...                           */
  307.                               /*     oder 0 User, 2 Level-2, 4 Level-4    */
  308.     char             l2fflg;  /*   Level 2 Frameflag / PID :              */
  309.                               /*     RX: PID                              */
  310.                               /*     TX: PID / s.o. T2FT1ST/T2FUS         */
  311.     char             l2port;  /*   0 = HDLC, 1 = RS232-Crosslink          */
  312.     char             morflg;  /*   "more follows flag" fuer Pakete, die   */
  313.                               /*   durch zusaetzlichen Netzwerkheader zu  */
  314.                               /*   lang wuerden und in 2 Frames           */
  315.                               /*   aufgetrennt wurden                     */
  316.                               /*     YES = das naechste Frame gehoert zu  */
  317.                               /*           diesem Paket                   */
  318.                               /*     NO  = sonst                          */
  319.     char             rsvd[10];/*   (damit insgesamt Laenge wie mb)        */
  320.     TIMEBL           btime;   /*   Buffer-Time fuer Zeit/Datum-Stamps     */
  321.     char            rsvd2[32];/* FEF */
  322.  
  323.   } MBHEAD;
  324.  
  325.  
  326. /* ACHTUNG: mb muss genauso lang sein wie mbhead !                        */
  327.  
  328. typedef struct mb             /* "message buffer",                        */
  329.   {                           /* allgemeiner Datenbuffer :                */
  330.     struct mb *nextmb;        /*   naechster Eintrag in Liste             */
  331.     struct mb *prevmb;        /*   vorheriger Eintrag in Liste            */
  332.     char       data[64];      /*   Daten           [DG2FEF]               */
  333.   } MB;
  334.  
  335.  
  336.  
  337. typedef struct stentry        /* "state table entry",                     */
  338.   {                           /* ein Eintrag in der State-Table :         */
  339.     VOID       (* func)();    /*   Zustandsuebergangsfunktion             */
  340.     char       newstate;      /*   neuer Zustand                          */
  341.   } STENTRY;
  342.  
  343.  
  344. /* Ende von L2.H */
  345.